package com.rjh.base.io.file;

import java.io.File;
import java.io.FilenameFilter;
import java.util.Objects;
import java.util.regex.Pattern;

public class PrintFilePath {

    public static void main(String[] args) {
        File path = new File("E:\\迅雷下载");

        String[] list = path.list(new DirFilter(".+.zip"));
        for (String s : list) {
            System.out.println(s);
        }

        // printPath(path);
    }

    private static void printPath(File file){
        if (Objects.nonNull(file)){
            File[] files = file.listFiles();
            if (Objects.nonNull(files)){
                for (File item : files) {
                    if (item.isDirectory()){
                        printPath(item);
                    }else{
                        System.out.println(item.getAbsoluteFile());
                    }
                }
            }
        }
    }
}


class DirFilter implements FilenameFilter{

    private Pattern pattern;

    public DirFilter(String regex) {
        this.pattern = Pattern.compile(regex);
    }

    @Override
    public boolean accept(File dir, String name) {
        return pattern.matcher(name).matches();
    }
}